package it.gius.pe.mains;

import it.gius.pe.Shape.BadShapeException;
import it.gius.pe.Shape.Polygon;
import it.gius.processing.gjkTest.GjkFinalApplet;
import it.gius.processing.gjkTest.GjkPolyPolyStepToStep;
import it.gius.processing.gjkTest.MinkDiffApplet;
import it.gius.processing.util.PAppletManager;
import it.gius.processing.util.ProcessingGraphicException;

import java.util.concurrent.Semaphore;

import org.jbox2d.common.Vec2;

public class GjkMainPolyPolyStepToStep {

	/**
	 * @param args
	 */
	
	
	static Polygon poly1,poly2 = null;
	
	public static void main(String[] args) {
		initShapes();
		
		Polygon[] array = new Polygon[2];
		array[0] = poly1;
		array[1] = poly2;
		
		Semaphore mutex = new Semaphore(1);
		
		GjkPolyPolyStepToStep gjkApplet = new GjkPolyPolyStepToStep(array);
		boolean exitOnLastDisposed = false;
		boolean manualStart = true;
		PAppletManager manager = new PAppletManager(exitOnLastDisposed,manualStart);


		try {
			manager.startAndAddApplet(new String[]{"--location=150,130"},
					gjkApplet,PAppletManager.DISPOSE_ALL);
			
		} catch (ProcessingGraphicException e) {
			e.printStackTrace();
			System.exit(1);
		}
		

	}
	
	
	private static void initShapes()
	{
		poly1 = new Polygon();

		//convex polygon
		poly1.addVertex(new Vec2(20,10));
		poly1.addVertex(new Vec2(2,30));
		poly1.addVertex(new Vec2(40,40));
		poly1.addVertex(new Vec2(50,20));

		
		try {
			poly1.endPolygon();
		} catch (BadShapeException e) {
			e.printStackTrace();
			System.out.println("bad shape 1");
			poly1 = null;
		}
		
		poly1.setPosition(new Vec2(162,116f));
		//poly1.setVelocity(new Vec2(1,1.5f));	
		
		
		poly2 = new Polygon();

		//convex polygon
		poly2.addVertex(new Vec2(20,15));
		poly2.addVertex(new Vec2(12,50));
		poly2.addVertex(new Vec2(60,50));
		poly2.addVertex(new Vec2(50,20));

		
		try {
			poly2.endPolygon();
		} catch (BadShapeException e) {
			e.printStackTrace();
			System.out.println("bad shape 2");
			poly2 = null;
		}
		
		poly2.setPosition(new Vec2(185,149f));
		//poly2.setVelocity(new Vec2(-0.5f,-1));	


	}


}
